<template>
	<view class="agent-manager-layout">
		<!-- 头部统计信息 -->
		<view class="manager-count-box">
			<view class="count-item">
				<text>代理商总数(人)</text>
				<text class="count-text">{{dataInfo.agentTotal}}</text>
			</view>
			<view class="count-bottom">
				<view class="count-item count-item-bottom">
					<text>直属代理商数(人)</text>
					<text class="count-item-bottom-text">{{dataInfo.directCount}}</text>
				</view>
				<view class="count-item count-item-bottom">
					<text>下级代理商数(人)</text>
					<text class="count-item-bottom-text">{{dataInfo.notDirectCount}}</text>
				</view>
			</view>
		</view>
		<!-- 头部信息 -->
		<view class="manager-header">
			<text>我的代理商</text>
			<text>仅显示直属的代理商数据</text>
		</view>
		<!-- 我的列表 -->
		<view class="manager-card">
			<view class="manager-card-top" @tap="showMyAgentList">
				<image src="/static/home/agent_list_icon.png" mode="aspectFit"></image>
				<text class="manager-card-top-text">我的代理商列表</text>
				<xh-icon icon="icon_jiantou" style="margin-left: auto;"></xh-icon>
			</view>
			<view class="manager-card-line"></view>
			<view class="manager-card-bottom">
				<view class="manager-card-bottom-item">
					<text>本月新增</text>
					<text>{{dataInfo.monthNewAgentCount}}</text>
				</view>
				<view class="manager-card-bottom-item">
					<text>当天新增</text>
					<text>{{dataInfo.dayNewAgentCount}}</text>
				</view>
			</view>
		</view>
		<!-- 异常代理商和未认证代理商 -->
		<view class="manager-card" style="margin-top: 30rpx;">
			<view class="manager-card-top" @tap="showFailAgentList">
				<image src="/static/home/agent_yc_icon.png" mode="aspectFit"></image>
				<text class="manager-card-top-text">异常代理商列表</text>
				<view class="manager-card-top-right">
					<text>总{{dataInfo.abnormalAgentCount}}人</text>
					<xh-icon icon="icon_jiantou" style="margin-left: auto;"></xh-icon>
				</view>
			</view>
			<view class="manager-card-line"></view>
			<view class="manager-card-top" @tap="showNoAuthAgentList">
				<image src="/static/home/agent_wrz_icon@2x.png" mode="aspectFit"></image>
				<text class="manager-card-top-text">未认证代理</text>
				<view style="margin-left: auto;color: #5F56EF;font-size: 26rpx;display: flex;align-items: center;">
					<text>邀请展业</text>
					<xh-icon icon="icon_jiantou" color="#5F56EF" style="margin-left: auto;"></xh-icon>
				</view>
			</view>
		</view>
		<!-- 运营工具 -->
		<view style="padding: 20rpx 0;font-size: 30rpx;font-weight: bold;">
			<text>运营工具</text>
		</view>
		<view class="manager-card manager-utils">
			<view class="manager-utils-item" @tap="showAddAgent">
				<image src="/static/home/agent_add_icon.png" mode="aspectFit"></image>
				<text>新增代理</text>
			</view>
			<view class="manager-utils-item" @tap="showPolicyConfig">
				<image src="/static/home/agent_policy_icon.png" mode="aspectFit"></image>
				<text>政策配置</text>
			</view>
			<view class="manager-utils-item" @tap="showHuoKuanManager">
				<image src="/static/home/agent_hk_icon.png" mode="aspectFit"></image>
				<text>货款管理</text>
			</view>
			<view class="manager-utils-item" @tap="showReport">
				<image src="/static/home/home_menu_icon5@2x.png" mode="aspectFit"></image>
				<text>运营报表</text>
			</view>
		</view>
	</view>
</template>

<script setup>
	import { onLoad } from '@dcloudio/uni-app'
	import { ref } from 'vue'
	import { getAgentManagerStatistics } from '@/common/api/api.js'
	const dataInfo = ref({
		agentTotal: 0,
		directCount: 0,
		notDirectCount: 0,
		monthNewAgentCount: 0,
		dayNewAgentCount: 0,
		abnormalAgentCount: 0
	})
	// 我的代理商列表
	const showMyAgentList = () => {
		uni.navigateTo({
			url: '/pages/home/agent-manager/agent-list/agent-list?type=我的代理商列表'
		})
	}
	// 异常代理商列表
	const showFailAgentList = () => {
		uni.navigateTo({
			url: '/pages/home/agent-manager/abnormal-agent/abnormal-agent'
		})
	}
	// 未认证代理商列表
	const showNoAuthAgentList = () => {
		uni.navigateTo({
			url: '/pages/home/agent-manager/no-auth-agent/no-auth-agent'
		})
	}
	// 新增代理
	const showAddAgent = () => {
		uni.navigateTo({
			url: '/pages/home/zy-tools/add-agent/add-agent'
		})
	}
	// 政策配置
	const showPolicyConfig = () => {
		uni.navigateTo({
			url: '/pages/home/agent-manager/agent-list/agent-list?type=政策配置'
		})
	}
	// 货款管理
	const showHuoKuanManager = () => {
		uni.navigateTo({
			url: '/pages/home/agent-manager/agent-list/agent-list?type=货款管理'
		})
	}
	// 运营报表
	const showReport = () => {
		uni.navigateTo({
			url: '/pages/home/agent-manager/agent-list/agent-list?type=代理商报表'
		})
	}
	// 获取代理商统计数据
	const loadData = async () => {
		const res = await getAgentManagerStatistics()
		dataInfo.value = res.result
	}
	onLoad(() => {
		loadData()
	})
</script>

<style lang="scss" scoped>
	.agent-manager-layout {
		background-color: #fff;
		padding: 20rpx 30rpx;
		min-height: 100vh;

		.manager-count-box {
			background-image: url('/static/operate/yy_byjy_bg@2x.png');
			background-size: 100% 100%;
			background-repeat: no-repeat;
			padding: 40rpx;

			.count-item {
				display: flex;
				flex-direction: column;
				align-items: center;
				color: #fff;
				font-size: 30rpx;

				.count-text {
					font-size: 68rpx;
					margin-top: 10rpx;
				}
			}

			.count-bottom {
				display: flex;
				align-items: center;
				justify-content: space-around;
				margin-top: 30rpx;

				.count-item-bottom {
					font-size: 26rpx;
				}

				.count-item-bottom-text {
					font-size: 40rpx;
					margin-top: 10rpx;
				}
			}
		}

		.manager-header {
			display: flex;
			flex-direction: column;
			padding: 30rpx 0;
			font-size: 30rpx;

			text:nth-child(1) {
				font-weight: bold;
			}

			text:nth-child(2) {
				color: $xh-color-9;
				font-size: 24rpx;
				margin-top: 10rpx;
			}
		}

		.manager-card {
			border: 1px solid #eee;
			border-radius: 20rpx;
			padding: 20rpx;

			.manager-card-top {
				display: flex;
				align-items: center;

				.manager-card-top-text {
					font-size: 30rpx;
					font-weight: bold;
					margin-left: 10rpx;
				}
				.manager-card-top-right{
					display: flex;
					align-items: center;
					margin-left: auto;
					color: $xh-color-9;
					font-size: 26rpx;
				}
				image {
					width: 80rpx;
					height: 80rpx;
				}
			}

			.manager-card-line {
				margin: 20rpx 0;
				height: 1px;
				background-color: #eee;
				transform: scaleY(0.5);
			}

			.manager-card-bottom {
				display: flex;
				align-items: center;
				justify-content: space-around;

				.manager-card-bottom-item {
					display: flex;
					flex-direction: column;
					align-items: center;
					color: $xh-color-9;
					font-size: 26rpx;

					text:nth-child(2) {
						font-size: 32rpx;
						color: $xh-color-3;
						font-weight: bold;
					}
				}
			}

		}

		.manager-utils {
			display: grid;
			grid-template-columns: repeat(4, 1fr);
			grid-gap: 20rpx;

			.manager-utils-item {
				display: flex;
				flex-direction: column;
				align-items: center;
				font-size: 26rpx;
				color: $xh-color-6;

				image {
					width: 80rpx;
					height: 80rpx;
				}
			}
		}
	}
</style>